package itheima02;

import java.io.*;
import java.util.*;

/**
 * @author xxx
 * @date 2020/12/23 17:29
 * @description
 */
public class Test {
    public static void main(String[] args) throws IOException {
        //使用文件字符缓冲流将day12/csbnosort.txt文件重新进行排列，并复制到另一个文件中
        BufferedReader bufferedReader=new BufferedReader(new FileReader("day12/csbnosort.txt"));
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("day12/csbnop.txt"));

        Map<Integer,String>map=new HashMap();
        String line;
        while ((line=bufferedReader.readLine())!=null){
          String[] arg=line.split("\\.");
            System.out.print(arg[0]);
          map.put(Integer.parseInt(arg[0]),arg[1]);
        }
        //Set<Integer>set=map.keySet();
        //Collections.sort(set);报错，list集合特有方法
        List<Integer>list=new LinkedList(map.keySet());
        Collections.sort(list);
        System.out.println(list);

        for (Integer integer : list) {
            System.out.println(integer+"."+map.get(integer));
            bufferedWriter.write(integer+"."+map.get(integer));
            bufferedWriter.newLine();
        }
        bufferedReader.close();
        bufferedWriter.close();

    }
}
